home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Network / Remote / Remote Restart < prev   
Encoding:
Text File  |  1999-03-04  |  5.0 KB  |  206 lines  |  [TEXT/ToyS]

  1. (*
  2. V1.02 ◊ This script is PD 1998 by AKUA interactive media AG.
  3.  
  4. Drag items from remote machines onto this script to tell them to 
  5.  quit.
  6.  
  7. V1.02 - Use new KeyChain routines.
  8. V1.01 - Use new gossip functionality.
  9. V1.0 - Start
  10. *)
  11.  
  12.  
  13. -- User setable properties
  14. property kasAllowAlerts : true -- Set to false to stop any alerts from appearing
  15. property kasServerAlerts : true -- Set to false to stop warnings about missed servers
  16. property kasFinder : "Finder" -- name of application to open RemoteLaunchers
  17. property kasAppendage : " ->" -- Appended to file name if we can't use original
  18.  
  19. -- Internal/User setable globals
  20. property kasLinkNeed : false
  21. property kasLinkUserDft : "CasaVision" -- Our friend on all machines
  22. property kasLinkPassDft : "" -- Our friend's password on all machines
  23.  
  24. global gasLinkSet -- Has the friend been looked up?
  25. global gasLinkUser -- Used to connect (KeyChain Lookup)
  26. global gasLinkPass
  27.  
  28. -- Internal globals
  29. global gasOurZone -- Set to zone of gasOurAlias
  30. global gasOurServer -- Set to server of gasOurAlias
  31. global gasOurVol -- Name of volume alias resides on
  32. global gasOurAlias -- The alias we own
  33. global gasOurName -- Name of original alias
  34.  
  35.  
  36. on open fsObjs
  37.     set gasLinkSet to false
  38.     
  39.     repeat with fsObj in fsObjs
  40.         OpenOne(fsObj)
  41.     end repeat
  42. end open
  43.  
  44.  
  45. on OpenOne(fsObj)
  46.     set aInfo to alias info from fsObj
  47.     
  48.     set gasOurZone to alias zone of aInfo
  49.     set gasOurServer to alias server of aInfo
  50.     set gasOurVol to alias volume of aInfo
  51.     GetFriend(false)
  52.     
  53.     RemoteOpen(fsObj)
  54. end OpenOne
  55.  
  56.  
  57. on RemoteOpen(fileAlias)
  58.     talk as user gasLinkUser ¬
  59.         with password gasLinkPass ¬
  60.         on server gasOurServer ¬
  61.         in AppleTalk zone gasOurZone
  62.     
  63.     try
  64.         -- Don't wait for a response, assume the aliases are correct
  65.         tell application kasFinder of machine gasOurServer ¬
  66.             of zone gasOurZone to «event fndrrest»
  67.     on error err
  68.         if (kasServerAlerts) then
  69.             ShowConnectAlert(myApp, err)
  70.         else
  71.             beep
  72.         end if
  73.     end try
  74. end RemoteOpen
  75.  
  76.  
  77. on GetFriend(override) -- Should later use some modifier key to override?!?
  78.     GetOneFriend(override)
  79. end GetFriend
  80.  
  81.  
  82. on GetOneFriend(override)
  83.     set isLink to true -- Only linking in this script!
  84.     set userMode to "linking"
  85.     set passButtons to {"Cancel", "OK"}
  86.     set passButton to 2
  87.     
  88.     if (gasLinkSet) then
  89.         set defUser to gasLinkUser
  90.         set defPass to gasLinkPass
  91.     else
  92.         set defUser to kasLinkUserDft
  93.         set defPass to kasLinkPassDft
  94.     end if
  95.     
  96.     set usrPwd to KeyChainLookUp(gasOurZone, gasOurServer, isLink)
  97.     
  98.     if (override or usrPwd is {}) then
  99.         set chosen to display dialog ¬
  100.             "Enter the friendly " & userMode & ¬
  101.             " user's name…" default answer defUser ¬
  102.             default button 2 with icon note
  103.         
  104.         if (the button returned of chosen is "OK") then
  105.             set defUser to the text returned of chosen
  106.         else
  107.             return
  108.         end if
  109.         
  110.         set chosen to display dialog ¬
  111.             "Enter the friendly " & userMode & ¬
  112.             " user's password…" buttons passButtons ¬
  113.             default answer defPass default button passButton with icon note
  114.         
  115.         if (the button returned of chosen is not "Cancel") then
  116.             set defPass to the text returned of chosen
  117.         else
  118.             return
  119.         end if
  120.         
  121.         -- Save encrypted user/pass for future access
  122.         KeyChainSave(gasOurZone, gasOurServer, isLink, defUser, defPass, "")
  123.     else
  124.         set defUser to item 1 of usrPwd
  125.         set defPass to item 2 of usrPwd
  126.     end if
  127.     
  128.     set gasLinkSet to true
  129.     set gasLinkUser to defUser
  130.     set gasLinkPass to defPass
  131. end GetOneFriend
  132.  
  133.  
  134. on PutAwayVol(volName)
  135.     -- Volume
  136.     try
  137.         tell application "Finder" to put away item named volName
  138.     on error
  139.         beep
  140.     end try
  141. end PutAwayVol
  142.  
  143.  
  144. on IsVolMounted(volName)
  145.     -- Volume
  146.     try
  147.         set x to (volName & ":") as alias
  148.         return true
  149.     on error
  150.         return false
  151.     end try
  152. end IsVolMounted
  153.  
  154.  
  155. on ShowMountAlert()
  156.     ShowServerAlert("Couldn't mount volume " & gasOurVol & ¬
  157.         " from " & gasOurServer ¬
  158.         & " in zone " & gasOurZone)
  159. end ShowMountAlert
  160.  
  161.  
  162. on ShowConnectAlert(appName, msg)
  163.     ShowServerAlert("Couldn't connect to " & appName & " on " & ¬
  164.         gasOurServer & " in zone " & gasOurZone & return & return & ¬
  165.         "(" & msg & ")")
  166. end ShowConnectAlert
  167.  
  168.  
  169. on ShowServerAlert(msg)
  170.     set choice to ¬
  171.         display dialog msg buttons {"Reenter Password", "OK"} ¬
  172.             default button 2 with icon stop
  173.     
  174.     if (button returned of choice is not "OK") then GetFriend(true)
  175. end ShowServerAlert
  176.  
  177.  
  178. property kasKeyChainPassword : "PowerScript" -- Encrypt stored data with this
  179. property kasPrefsFileName : "PowerScript Prefs" -- File name in <Preferences>
  180.  
  181. on KeyChainLookUp(zoneName, serverName, isLinking)
  182.     set prefOwner to "πSRV"
  183.     if (isLinking) then set prefOwner to "πLNK"
  184.     
  185.     try
  186.         set myKeyData to load preference named (zoneName & ":" & serverName) ¬
  187.             of type prefOwner in file named kasPrefsFileName
  188.     on error
  189.         return {}
  190.     end try
  191.     
  192.     return (encrypt the data myKeyData with password kasKeyChainPassword)
  193. end KeyChainLookUp
  194.  
  195.  
  196. on KeyChainSave(zoneName, serverName, isLinking, usr, pwd, ntPwd)
  197.     set myKey to encrypt the data {usr, pwd, ntPwd} with password kasKeyChainPassword
  198.     
  199.     set prefOwner to "πSRV"
  200.     if (isLinking) then set prefOwner to "πLNK"
  201.     
  202.     save preference myKey named (zoneName & ":" & serverName) ¬
  203.         of type prefOwner ¬
  204.         in file named kasPrefsFileName
  205. end KeyChainSave
  206.